﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.mNC.Common;
using System.Runtime.InteropServices;
using Lamex.NC.Model;
using DevExpress.XtraEditors.Popup;
using Lamex.Base;
using Lamex.NC.BLL;
using DevExpress.XtraSplashScreen;
using Lamex.Common;
using DevExpress.XtraBars.Design;
using Lamex.Interface;
using System.IO;
using Lamex.Library.UI;
using System.Threading;
using DevExpress.Utils.Svg;
using System.Xml;
using DevExpress.Utils.About;
using DevExpress.Utils.DPI;
using Lamex.Library.CommonClass;

namespace Lamex.mNC.UI
{
    public partial class frmNC_Convert_CheckDKSJR_Processing : frmBaseChild
    {
        IntPtr handle;
        [DllImport("user32.dll", SetLastError = true)]

        private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        private const int GWL_STYLE = (-16);
        private const int WS_VISIBLE = 0x10000000;
        const Int32 WS_BORDER = (Int32)0x00800000L;
        const Int32 WS_THICKFRAME = (Int32)0x00040000L;
        const Int32 SWP_NOMOVE = 0x0002;
        const Int32 SWP_NOSIZE = 0x0001;
        const Int32 SWP_NOZORDER = 0x0004;
        const Int32 SWP_FRAMECHANGED = 0x0020;
        const Int32 SW_MAXIMIZE = 3;
        IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        
        //[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        //private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
        [DllImport("user32", EntryPoint = "SetWindowLong", SetLastError = true)]
        private static extern uint SetWindowLong(
        IntPtr hwnd,
        int nIndex,
        int dwNewLong
        );
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        static extern Int32 SetWindowPos(IntPtr hWnd,
   IntPtr hWndInsertAfter,
   Int32 X,
   Int32 Y,
   Int32 cx,
   Int32 cy,
   UInt32 uFlags
 );
        string PartNo = "";
        string TargetPath = "";
        bool isShow = true;
        string tipPath = "";
        string rountingType = "";
        string UpoldStr = "";
        string pathFileName = "";
        string DownOldStr = "";

        string LeftOldStr = "";

        string RightOldStr = "";
        string UpoldValue = "";

        string DownOldValue = "";

        string LeftOldValue = "";

        string RightOldValue = "";

        string cuttingType = "";
        string machineType = "";
        int widthNm1 = 0;
        int widthNm2 = 0;
        List<string> egdeList = new List<string>();
        string nC_DK_SJ01 = "";

        public frmNC_Convert_CheckDKSJR_Processing(string PartNo, string targetPath, string tipPath, string pathFileName)
        {
            //nC_DK_SJ01 = this.nC_DK_SJ01;
            egdeList.Clear();
            InitializeComponent();
            this.TargetPath = targetPath;
            Clipboard.SetText(TargetPath);
            if (handle == IntPtr.Zero)
                handle = FindWindow(null, "Creo Parametric");//Creo Parametric
            InsertWindow insertwin = new InsertWindow(panel1, "", handle);
            this.PartNo = PartNo;
            txtPart_No.Text = PartNo;
            this.tipPath = tipPath;
            this.pathFileName = pathFileName;
            //this.TargetPath = "L:" + targetPath.Trim().ToLower().Replace(@"\\TX-FS10\tx-fs1\LAMEX".Trim().ToLower(), " ").Trim();

            this.Load += new EventHandler(frmNC_Convert_CheckDKSJR_Processing_Load);

        }

        public void InitLoad(string PartNo, string targetPath, string tipPath, string pathFileName)
        {
            //nC_DK_SJ01 = this.nC_DK_SJ01;
            egdeList.Clear();
            //targetPath= "L:" + targetPath.Trim().ToLower().Replace(@"\\TX-FS10\tx-fs1\LAMEX".Trim().ToLower(), " ").Trim();
            this.TargetPath = targetPath;
            Clipboard.SetText(TargetPath);
            //radioGroup1.Enabled = false;
            chkPartConvert.Checked = false;
            this.PartNo = PartNo;
            txtPart_No.Text = PartNo;
            this.tipPath = tipPath;
            this.pathFileName = pathFileName;
            frmNC_Convert_CheckDKSJR_Processing_Load(null, null);
            ClearCutting();
            //ShowRountingTips();

            //Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoFileOp.exe;L:\Share\MurphyMin\CreoBox\");


        }
        private void frmNC_Convert_CheckDKSJR_Processing_Load(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(tipPath);
            string path = fi.DirectoryName;
            string movePath = fi.DirectoryName;
            string name = fi.Name;
            path = path + @"\" + pathFileName + ".csv";
            
            try
            {

                DataTable dtCsv = new DataTable();
                //if (true) return;
                Lamex.Common.ExecelHelper.csv2dt(path, 0, dtCsv);
                //开始填充数据
                cboxGrain_Direct.Text = dtCsv.Rows[0]["木纹方向"].ToString();
                chkPartConvert.Checked = dtCsv.Rows[0]["旋转标识"].ToString() == "0" ? false : true;
                txt_Width1.Text = dtCsv.Rows[0]["阔度_1"].ToString();
                txt_Width2.Text = dtCsv.Rows[0]["阔度_2"].ToString();
                cboxPart_Thick.Text = dtCsv.Rows[0]["厚度"].ToString();
                cmb_Up.Text = dtCsv.Rows[0]["封边_C1"].ToString();
                cmb_Down.Text = dtCsv.Rows[0]["封边_C2"].ToString();
                cmb_Left.Text = dtCsv.Rows[0]["封边_C3"].ToString();
                cmb_Right.Text = dtCsv.Rows[0]["封边_C4"].ToString();
                cmb_UpValue.Text= dtCsv.Rows[0]["封边_T1"].ToString();
                cmb_DownValue.Text = dtCsv.Rows[0]["封边_T2"].ToString();
                cmb_LeftValue.Text = dtCsv.Rows[0]["封边_T3"].ToString();
                cmb_RightValue.Text = dtCsv.Rows[0]["封边_T4"].ToString();

                CuttingWay();
                //loading all select values
                //loadMaterialInfo();

                //load tip image into form
                List<string> lst = new List<string>();
                lst.Add(tipPath);
                ucShowPic1.LoadImageList(lst);

                if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                {

                    Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoFileOp.exe;L:\Share\MurphyMin\CreoBox\");

                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
        private void uc_DoubleClick(object sender, EventArgs e)
        {
            pictureEdit2_DoubleClick(null, null);
            //DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql("");
        }
    /// <summary>
    /// 工艺路线提示ReturnCuttingType
    /// </summary>
    private void ShowRountingTips()
        {
            
            //DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql("");
        }

        //public byte[] GetByteImage(Image img)
        //{
        //    byte[] bt = null;
        //    if (!img.Equals(null))
        //    {
        //        using (MemoryStream mostream = new MemoryStream())
        //        {
        //            Bitmap bmp = new Bitmap(img);
        //            bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流

        //            bt = new byte[mostream.Length];
        //            mostream.Position = 0;//设置留的初始位置
        //            mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
        //        }
        //    }
        //    return bt;
        //}
        /// <summary>
        /// select cuttingway type
        /// </summary>
        private void CuttingWay()
        {
            //PartNo = "9033233080";
            NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
            StringBuilder str = new StringBuilder();
            str.Append("物料号码:"+PartNo + "\r\n");
            DataTable dt = BaseBuildSql.GetDataTableBySql(@" select b.* from IE_Part_Routing a 
                                                             join IE_Routing_Combination b on a.GROUP_CODE = b.GROUP_CODE
                                                             where a.PART_NO = '"+PartNo+"'");
            if(dt.Rows.Count!=0)
            {
                string rounting = dt.Rows[0]["ROUTING_CODE"].ToString();
                rountingType = rounting;
                if (!string.IsNullOrEmpty(rounting))
                {
                    cuttingType = ReturnCuttingType.GetCuttingType(rounting);
                    if ("COMBIMA" == cuttingType)
                    {
                        str.Append("开料方式：" + "COMBIMA" + "\r\n");
                        //radioGroup1.SelectedIndex = 0;
                        

                    }
                    else if ("BIMA" == cuttingType)
                    {
                        str.Append("开料方式：" + "BIMA" + "\r\n");
                        //radioGroup1.SelectedIndex = 1;
                    }
                    else if ("小板线" == cuttingType)
                    {
                        str.Append("开料方式：" + "小板线" + "\r\n");
                        //radioGroup1.SelectedIndex = 2;

                        
                    }
                    else if ("斜边线" == cuttingType)
                    {
                        str.Append("开料方式：" + "斜边线" + "\r\n");
                        //radioGroup1.SelectedIndex = 2;

                        
                        //radioGroup1.SelectedIndex = 3;
                    }
                    //if ((!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                    //{
                    //    if (model.THICK != null)
                    //        cboxPart_Thick.Text = model.THICK.ToString();
                    //    if (model.FINISH_WIDTH != null)
                    //        txt_Width1.Text = model.FINISH_WIDTH.ToString();
                    //    if (model.FINISH_DEPTH != null)
                    //        txt_Width2.Text = model.FINISH_DEPTH.ToString();
                    //    cboxPart_Thick.ReadOnly = false;
                    //    txt_Width1.ReadOnly = false;
                    //    txt_Width2.ReadOnly = false;
                    //}
                   //机械加工：
                    machineType = ReturnCuttingType.GetMachineType(rounting);
                    
                    str.Append("加工机械：" + machineType + "\r\n");
                    str.Append("工艺路线：" + dt.Rows[0]["ROUTING_DESC"].ToString() + "\r\n");
                    memoEdit1.Text = str.ToString();



                    

                }
                
            }
            //radioGroup1.Properties.Items[3].Enabled = true;


           
        }
        /// <summary>
        /// load MaterialInfo to rubber edge config color
        /// </summary>
        private void loadMaterialInfo()
        {
            cmb_Up.Properties.Items.Clear();
            cmb_Down.Properties.Items.Clear();
            cmb_Left.Properties.Items.Clear();
            cmb_Right.Properties.Items.Clear();
            DataTable dt = BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info] order by CTRL_SEQUENCE ");
            if(dt.Rows.Count!=0)
            {
                foreach(DataRow dr in dt.Rows)
                {
                    cmb_Up.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Down.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Left.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Right.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                }
            }
        }
        
        private void frmNC_Converting_Processing_DKSJR_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width / 2;
        }

        /// <summary>
        /// if chkpartconvert is true , wrap width1 and width2 values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkPartConvert_CheckedChanged(object sender, EventArgs e)
        {
            string tempValue = "";
            if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
            {
                if (cboxGrain_Direct.Text.ToLower().Contains("h"))
                    cboxGrain_Direct.Text = "V_直纹";
                else if (cboxGrain_Direct.Text.ToLower().Contains("v"))
                    cboxGrain_Direct.Text = "H_横纹";
                else
                    cboxGrain_Direct.Text = "N_无纹";
            }
            else
            {
                tempValue = txt_Width2.Text;
                txt_Width2.Text = txt_Width1.Text;
                txt_Width1.Text = tempValue;
                //NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                //if (model != null)
                //{
                if (cboxGrain_Direct.Text.ToLower().Contains("h"))
                    cboxGrain_Direct.Text = "V_直纹";
                else if (cboxGrain_Direct.Text.ToLower().Contains("v"))
                    cboxGrain_Direct.Text = "H_横纹";
                else
                    cboxGrain_Direct.Text = "N_无纹";
                //}
            }

        }
        /// <summary>
        /// select index decision detp value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnImport_Click(object sender, EventArgs e)
        {
           

        }
        private double ReValue(double fristValue, double SecondValue)
        {
            double dValue = fristValue + SecondValue;
            if (dValue == 1.2)
                dValue = 1.5;
            if (dValue == 0.6)
                dValue = 0.5;
            if (dValue == 2)
                dValue = 2;
            if (dValue == 2.6)
                dValue = 2.5;
            if (dValue == 4)
                dValue = 4;
            if (dValue == 0)
                dValue = 0;
            return dValue;

        }
        /// <summary>
        /// 判断是否为数字
        /// </summary>
        /// <param name="message"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        protected bool isNumberic(string message)
        {
         
            System.Text.RegularExpressions.Regex rex =
            new System.Text.RegularExpressions.Regex(@"^\d+$");
        
            if (rex.IsMatch(message))
            {
                return true;
            }
            else
                return false;
        }
        /// <summary>
        /// 提示
        /// </summary>
        private bool AlertMsg()
        {
            if (cmb_Up.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Down.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Left.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Right.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_UpValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_DownValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_LeftValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_RightValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            return true;
        }
        private void ClearCutting()
        {
            cmb_Up.Text = "";
            cmb_Down.Text = "";
            cmb_Left.Text = "";
            cmb_Right.Text = "";
            cmb_UpValue.Text = "";
            cmb_DownValue.Text = "";
            cmb_LeftValue.Text = "";
            cmb_RightValue.Text = "";
        }
        private void btnCheckComform_Click(object sender, EventArgs e)
        {
            try
            {
                NC_Convert_ProcessRecordInfo bll = BaseFactory<NC_Convert_ProcessRecord>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                if (bll != null)
                {
                    if (bll.NC_STATE.Trim() == "待修改")
                    {
                        XtraMessageBox.Show("待修改，无法审核！");
                        return;
                    }

                    if (bll.NC_STATE.Trim() == "已审核")
                    {
                        XtraMessageBox.Show("已审核，请勿重复确认！");
                        return;
                    }
                    bll.NC_STATE = "已审核";
                    if (BaseFactory<NC_Convert_ProcessRecord>.Instance.Update(bll))
                    {
                        //需要解除文件权限

                        XtraMessageBox.Show("审核成功！");

                        return;
                    }
                    else
                    {
                        XtraMessageBox.Show("审核失败！");
                        return;
                    }
                }
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
              

        }
        
        private void cmb_Up_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Up.Text)) return;
            if (cmb_Up.Text.Length > 9)
            {
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Up.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Up.Text == "PVC_XXX_不封")
                        {
                            cmb_UpValue.Text = "0";
                            //cmb_UpValue.ReadOnly = true;
                        }
                            
                        else if (cmb_Up.Text == "PVC_NIL_不适用")
                        {
                            cmb_UpValue.Text = "0";
                            //cmb_UpValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            cmb_UpValue.Text = "";
                            //cmb_UpValue.ReadOnly = false;
                        }
                            
                    }
                    else
                    {
                        //cmb_UpValue.ReadOnly = false;
                        cmb_UpValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();

                    }
                    UpoldStr = cmb_Up.Text;
                }
                
            }
            UpoldValue = "";
        }

        private void cmb_Down_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Down.Text)) return;
            if (cmb_Down.Text.Length > 9)
            {
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Down.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Down.Text == "PVC_XXX_不封")
                        {
                            cmb_DownValue.Text = "0";
                            //cmb_DownValue.ReadOnly = true;
                        }
                            
                        else if (cmb_Down.Text == "PVC_NIL_不适用")
                        {
                            cmb_DownValue.Text = "0";
                            //cmb_DownValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            cmb_DownValue.Text = "";
                            //cmb_DownValue.ReadOnly = false;
                        }
                            
                    }
                    else
                    {
                        //cmb_DownValue.ReadOnly = true;
                        cmb_DownValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    DownOldStr = cmb_Down.Text;
                }
                
            }
        }

        private void cmb_Left_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Left.Text)) return;
            if (cmb_Left.Text.Length > 9)
            {

                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Left.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Left.Text == "PVC_XXX_不封")
                        {
                            cmb_LeftValue.Text = "0";
                            //cmb_LeftValue.ReadOnly = true;
                        }
                        
                        else if (cmb_Left.Text == "PVC_NIL_不适用")
                        {
                            cmb_LeftValue.Text = "0";
                            //cmb_LeftValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            //cmb_LeftValue.ReadOnly = false;
                            cmb_LeftValue.Text = "";
                        }
                            
                    }
                    else
                    {
                        //cmb_LeftValue.ReadOnly = false;
                        cmb_LeftValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    LeftOldStr = cmb_Left.Text;

                }
                
            }
        }

        private void cmb_Right_TextChanged(object sender, EventArgs e)
        {
            if (cmb_Right.Text.Length > 9)
            {
                if (cmb_Right.Text == RightOldStr) return;
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Right.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Right.Text == "PVC_XXX_不封")
                        {
                            //cmb_RightValue.ReadOnly = true;
                            cmb_RightValue.Text = "0";
                            
                        }   
                        else if (cmb_Right.Text == "PVC_NIL_不适用")
                        {
                            //cmb_RightValue.ReadOnly = true;
                            cmb_RightValue.Text = "0";
                        }
                        else
                        {
                            //cmb_RightValue.ReadOnly = false;
                            cmb_RightValue.Text = "";
                        }
                            
                    }
                    else
                    {
                        //cmb_RightValue.ReadOnly = false;
                        cmb_RightValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    RightOldStr = cmb_Right.Text;
                }
                
            }
        }

        /// 计算字符串中子串出现的次数
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="substring">子串</param>
        /// <returns>出现的次数</returns>
        static int SubstringCount(string str, string substring)
        {
            if (str.Contains(substring))
            {
                string strReplaced = str.Replace(substring, "");
                int count= (str.Length - strReplaced.Length) / substring.Length;
                if ((strReplaced.Length > 0 && count >0)|| (strReplaced.Length == 0 && count > 1)|| (strReplaced.Length == 0 && count == 0))
                    count = 2;
                else
                    count = 1;
                return count;
            }

            return 0;
        }

        private void cmb_UpValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_UpValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Up.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                UpoldValue = "";
                cmb_UpValue.Text = "";
                
            }

            if (UpoldValue == "")
                UpoldValue = cmb_UpValue.Text;
            //else
            //{
            //    int a = cmb_UpValue.Text.Split(new string[] { UpoldValue }, StringSplitOptions.None).Length - 1;
            //}

        }

        private void cmb_DownValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_DownValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Down.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                DownOldValue = "";
                cmb_DownValue.Text = "";

            }

            if (DownOldValue == "")
                DownOldValue = cmb_DownValue.Text;
        }

        private void cmb_LeftValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_LeftValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Left.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                LeftOldValue = "";
                cmb_LeftValue.Text = "";

            }

            if (LeftOldValue == "")
                LeftOldValue = cmb_LeftValue.Text;
        }

        private void cmb_RightValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_RightValue.Text)) return;
            if (string.IsNullOrEmpty(cmb_Right.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                RightOldValue = "";
                cmb_RightValue.Text = "";

            }

            if (RightOldValue == "")
                RightOldValue = cmb_RightValue.Text;
        }

        /// <summary>
        /// change form up and down
        /// </summary>
        /// <param name="sender"></param>
        //public override void DOChange(IButtonInfo sender)
        //{
            
        //        base.DOChange(sender);
        //}

        

        private void pictureEdit2_DoubleClick(object sender, EventArgs e)
        {
            if (isShow == true)
            {
                panelControl_Top.Hide();
                //panelControl_Top.AutoSize = true;
                //panelControl_Top.Height = 30;
                isShow = false;
            }
            else
            {
                panelControl_Top.Show();
                //panelControl_Top.AutoSize = true;
                //panelControl_Top.Height = 142;
                isShow = true;
            }
        }

        private void cmb_Up_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {

        }

        private void cmb_Up_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Up.Text)) return;
            if (cmb_Up.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(UpoldStr))
                {
                    if (SubstringCount(cmb_Up.Text, UpoldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Up.Text = "";
                        cmb_Up.EditValue = "";
                        UpoldStr = cmb_Up.Text;
                        return;
                    }
                    if(cmb_Up.Text!= UpoldStr)
                        cmb_Up.EditValue = "";

                }
                //else
                //    UpoldStr = cmb_Up.Text;
            }
        }

        private void cmb_Down_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Down.Text)) return;
            if (cmb_Down.Text.Length > 9)
            {

                if (!string.IsNullOrEmpty(DownOldStr))
                {
                    if (SubstringCount(cmb_Down.Text, DownOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Down.Text = "";
                        cmb_DownValue.Text = "";
                        DownOldStr = cmb_Down.Text;
                    }
                }
                
            }
        }

        private void cmb_Left_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Left.Text)) return;
            if (cmb_Left.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(LeftOldStr))
                {
                    if (SubstringCount(cmb_Left.Text, LeftOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Left.Text = "";
                        cmb_LeftValue.Text = "";
                        LeftOldStr = cmb_Left.Text;
                        return;
                    }
                }
            }
        }

        private void cmb_Right_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Right.Text)) return;
            if (cmb_Right.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(RightOldStr))
                {
                    if (SubstringCount(cmb_Right.Text, RightOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Right.Text = "";
                        cmb_RightValue.Text = "";
                        RightOldStr = cmb_Right.Text;
                        return;
                    }
                }
            }
        }

        
        private void cmb_UpValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_UpValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(UpoldValue))
            {
                int a = cmb_UpValue.Text.Split(new string[] { UpoldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_UpValue.Text.Length > UpoldValue.Length)
                    len = 1;
                if (a>=1&&len==1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    UpoldValue = "";
                    cmb_UpValue.Text = "";
                    //cmb_UpValue.Text = "";
                    
                    //return;
                }
            }
            
        }

        private void cmb_DownValue_KeyUp(object sender, KeyEventArgs e)
        {

            if (string.IsNullOrEmpty(cmb_DownValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(DownOldValue))
            {
                int a = cmb_DownValue.Text.Split(new string[] { DownOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_DownValue.Text.Length > DownOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    DownOldValue = "";
                    cmb_DownValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_LeftValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_LeftValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(LeftOldValue))
            {
                int a = cmb_LeftValue.Text.Split(new string[] { LeftOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_LeftValue.Text.Length > LeftOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    LeftOldValue = "";
                    cmb_LeftValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_RightValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_RightValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(RightOldValue))
            {
                int a = cmb_RightValue.Text.Split(new string[] { RightOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_RightValue.Text.Length > RightOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    RightOldValue = "";
                    cmb_RightValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_UpValue_SelectedIndexChanged(object sender, EventArgs e)
        {
            //UpoldValue = "";
        }

        private void ucShowPic1_DoubleClick(object sender, EventArgs e)
        {
           
        }

        private void ucShowPic1_UcDoubleClick(object sender, EventArgs e)
        {
            pictureEdit2_DoubleClick(null, null);
        }

        private void sbtnRefresh_Click(object sender, EventArgs e)
        {

        }

        private void cmbNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void cmbWidthType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbNum.Text))
            //{
            //    XtraMessageBox.Show("数据值不能空！");
            //    return;
            //}
            //if (cmbWidthType.Text=="空")
            //{
            //    cmbNum.Text = "0";
            //}
            //else if (cmbWidthType.Text == "阔度1方向" )
            //{
            //    if (cmbNum.Text == "2")
            //        txt_Width1.Text = (widthNm1 + 2).ToString();
            //    if (cmbNum.Text == "4")
            //        txt_Width1.Text = (widthNm1 + 4).ToString();
            //}
            //else if (cmbWidthType.Text == "阔度2方向" )
            //{
            //    if (cmbNum.Text == "2")
            //        txt_Width2.Text = (widthNm2 + 2).ToString();
            //    if (cmbNum.Text == "4")
            //        txt_Width2.Text = (widthNm2 + 4).ToString();
            //}

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
           
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            


        }

        private void btnAutoCheck_Click(object sender, EventArgs e)
        {
           
        }

        private void cmbWidth1_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbWidth1.Text)) cmbWidth1.Text = "0";
            //if (cmbWidth1.Text == "0") return;
            //if (cmbWidth1.Text == "2")
            //{
            //    txt_Width1.Text = (widthNm1 + 2).ToString();
            //}
            //else if (cmbWidth1.Text == "4")
            //{
            //    txt_Width1.Text = (widthNm1 + 4).ToString();
            //}
        }

        private void cmbWidth2_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbWidth2.Text)) cmbWidth1.Text = "0";
            //if (cmbWidth2.Text == "0") return;
            //if (cmbWidth2.Text == "2")
            //{
            //    txt_Width2.Text = (widthNm2 + 2).ToString();
            //}
            //else if (cmbWidth2.Text == "4")
            //{
            //    txt_Width2.Text = (widthNm2 + 4).ToString();
            //}
        }

        private void cmbThickness_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbThickness.Text)) cmbWidth1.Text = "0";
            //if (cmbThickness.Text == "0") return;
            //if (cmbThickness.Text == "2")
            //{
            //    cboxPart_Thick.Text = (widthNm2 + 2).ToString();
            //}
            //else if (cmbWidth2.Text == "4")
            //{
            //    cboxPart_Thick.Text = (widthNm2 + 4).ToString();
            //}
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            string dkProcessName = typeof(frmNC_Issue_Register).ToString();
            Form childProcess = MdiTools.ActiveChildWebBrowse((this.MdiParent as IMdiForm) as Form, dkProcessName);
            if (childProcess == null)
                MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmNC_Issue_Register(PartNo), sender as ToolStripMenuItem);
            else
            {
                if (childProcess != null)
                {
                    frmNC_Issue_Register frm = childProcess as frmNC_Issue_Register;
                    frm.initPartNo(PartNo);
                    frm.Show();
                }
            }

           
        }
    }
}